/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.goods.appweb;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.responseReturn.entity.ResultObject;
import com.jeesite.common.responseReturn.utils.CommonUtils;
import com.jeesite.common.responseReturn.web.Render;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.config.MyProps;
import com.jeesite.modules.goods.entity.ZtFinancial;
import com.jeesite.modules.goods.service.ZtFinancialService;
import com.jeesite.modules.util.TimeUtile;
import com.jeesite.modules.xcxAdmin.entity.ZtAdmin;
import com.jeesite.modules.xcxAdmin.service.ZtAdminService;

/**
 * 测试数据Controller
 * 
 * @author ThinkGem
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${frontPath}/ztFinancial")
public class AppZtFinancialController extends BaseController {


	@Autowired
	ZtFinancialService ztFinancialService;
	@Autowired
	ZtAdminService ztAdminService;
	
	@Autowired
	private MyProps myProps;
	
	/**
	 * 收支明细列表       佣金 1,2   ； 支出  3        ；提现   4
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public void listData( HttpServletRequest request,
			HttpServletResponse response,Model model) {
		
		String paramStr=CommonUtils.getParams(request);
		ResultObject res = new ResultObject();
		
		JSONObject jo=JSONObject.parseObject(paramStr);
		String adminid = jo.getString("adminid");
		
		String type = "";
		if(jo.get("type")!=null){
			type=jo.get("type").toString();
		}
		
		String pageNum = jo.getString("pageNum");
		if(StringUtils.isBlank(pageNum)){
			pageNum="1";
		}
	
		ZtFinancial ztFinancial=new ZtFinancial();
		ZtAdmin ztAdmin=new ZtAdmin();
		ztAdmin.setId(adminid);
		ztFinancial.setZtAdmin(ztAdmin);
		ztFinancial.setType(type);
		ztFinancial.setPageNum((Integer.valueOf(pageNum) - 1) * 15);
		if(jo.containsKey("createDateGte")){
			ztFinancial.setCreateDate_gte(jo.getDate("createDateGte"));
		}
		if(jo.containsKey("createDateLte")){
			ztFinancial.setCreateDate_lte(jo.getDate("createDateGte"));
		}
		ztFinancial.setAudit("2");
		List<ZtFinancial> ztFinancialList=ztFinancialService.getMh(ztFinancial);
		
		
		res.setResult(200L);
		res.setData(ztFinancialList);
		Render.renderString(response, res);
	}
	
	/**
	 * 我的粉丝列表
	 * @param request
	 * @param response
	 * @param model
	 */
	@RequestMapping(value = "myFans")
	@ResponseBody
	public void myFans( HttpServletRequest request,
			HttpServletResponse response,Model model) {
		
		String paramStr=CommonUtils.getParams(request);
		ResultObject res = new ResultObject();
		
		JSONObject jo=JSONObject.parseObject(paramStr);
		String adminid = jo.getString("adminid");
		String pageNum = jo.getString("pageNum");
		
		
		
		if(StringUtils.isBlank(pageNum)){
			pageNum="1";
		}
	
		ZtAdmin ztAdmin=new ZtAdmin();
		ztAdmin.setLastadmin(adminid);
		
		ztAdmin.setPageNum((Integer.valueOf(pageNum) - 1) * 15);
		
		String level = "";

		if(jo.get("level")!=null){
			level=jo.get("level").toString();
		}
		
		ztAdmin.setLevel(level);
	
		List<Map> ztAdminList=ztAdminService.getMyFans(ztAdmin);
		
		for(Map m : ztAdminList){
			
			long timeStamp = TimeUtile.timeStamp(m.get("endDate").toString(), null);
			m.put("endDate",TimeUtile.getTimeStr(timeStamp));
			
			if(StringUtils.isNotBlank(m.get("wximg").toString())&&!m.get("wximg").toString().startsWith("http")){
				m.put("wximg",myProps.getServerPath()+m.get("wximg").toString());
			}
		}
		
		res.setResult(200L);
		res.setData(ztAdminList);
		Render.renderString(response, res);
	}
	
}